package com.tyl.bk;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 *超时等待
 **/
//队列
public class BlockingQueueTest4 {

    public static void main(String[] args) throws InterruptedException {
        BlockingQueue blockingQueue= new ArrayBlockingQueue<>(3);
        blockingQueue.offer("a");
        blockingQueue.offer("b");
        blockingQueue.offer("c");
        blockingQueue.offer("d",2, TimeUnit.SECONDS);//超时等待结束之后结束
        System.out.println("=============================");
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll(2,TimeUnit.SECONDS));//超时等待两秒之后结束
    }
}

